﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace PublicClass
{
    public class PublicNoCad
    {

        #region 路径相关
        /// <summary>
        /// 系统的 应用程序目录
        /// </summary>
        /// <returns></returns>
        public static string GetAppDataPath()
        {
            return Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
        }
        /// <summary>
        /// 获取自己程序的路径
        /// </summary>
        /// <param name="name">自己程序名称相对路径</param>
        /// <returns></returns>
        public static string GetSelftUserPath(string appName = "wangafeiApp", string name = "UserAppData")
        {
            string path = System.IO.Path.Combine(GetAppDataPath(), System.IO.Path.Combine(appName, name));
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }

            return path;
        }
        /// <summary>
        /// 返回当前dll所在路径
        /// </summary>
        /// <returns>返回末尾没有下划线 例如: \\bin</returns>
        public static string GetDllPath()
        {
            string codeBase = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            string path = Uri.UnescapeDataString(uri.Path);
            return Path.GetDirectoryName(path);
        }
        /// <summary>
        /// 返回软件安装路径
        /// </summary>
        /// <returns>返回末尾有下划线 例如: wangafei\\</returns>
        public static string GetRootPath()
        {
            string strPath = GetDllPath();
            string WantedPath = strPath.Substring(0, strPath.LastIndexOf(@"\"));

            return WantedPath + "\\";
        }
        /// <summary>
        /// 返回sysdata，有下划线
        /// </summary>
        /// <returns>返回末尾有下划线 例如: Bin\\SysData\\</returns>
        public static string GetSysData()
        {
            string strLoadFile = GetRootPath() + "SysData\\";
            return strLoadFile;
        }
        #endregion


        #region 路径无关
        static public bool EqualDouble(double dLeft, double dRight, double dTol = 0.001)
        {
            double dOff = Math.Abs(dLeft - dRight);

            if (dOff < dTol)
                return true;

            return false;
        }
        #endregion
    }

    public class WinMsg
    {
        public const int WH_MOUSE_LL = 14;
        public const int WH_KEYBOARD_LL = 13;
        public const int WH_MOUSE = 7;
        public const int WH_KEYBOARD = 2;
        public const int WM_MOUSEMOVE = 0x200;
        public const int WM_LBUTTONDOWN = 0x201;
        public const int WM_RBUTTONDOWN = 0x204;
        public const int WM_MBUTTONDOWN = 0x207;
        public const int WM_LBUTTONUP = 0x202;
        public const int WM_RBUTTONUP = 0x205;
        public const int WM_MBUTTONUP = 0x208;
        public const int WM_LBUTTONDBLCLK = 0x203;
        public const int WM_RBUTTONDBLCLK = 0x206;
        public const int WM_MBUTTONDBLCLK = 0x209;
        public const int WM_MOUSEWHEEL = 0x020A;

        public const int WM_KEYDOWN = 0x100;
        public const int WM_KEYUP = 0x101;
        public const int WM_SYSKEYDOWN = 0x104;
        public const int WM_SYSKEYUP = 0x105;

        public const byte VK_SHIFT = 0x10;
        public const byte VK_CAPITAL = 0x14;
        public const byte VK_NUMLOCK = 0x90;
    }
}
